{extend name='common/_container'}
{block name="content"}
<div class="ibox float-e-margins">
<input type="hidden" name='extend_id' id='extend_id' value="{$info.extend_id}" />
	<div class="ibox-content">
		<div class="form-horizontal" id="CodeInfoForm">
			<div class="row">
				<div class="col-sm-12">
				<!-- form start -->
					<div class="form-group">
						<label class="col-sm-2 control-label">名称：</label>
						<div class="col-sm-9">
							<input type="text" autocomplete="off" id="title" value="{$info.title}" name="title" class="form-control" placeholder="请输入名称">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">数据库表名称：</label>
						<div class="col-sm-9">
							<input type="text" autocomplete="off" id="table_name" value="{$info.table_name}" name="table_name" class="form-control" placeholder="请输入数据库表名称">
						</div>
					</div>
					<div class="form-group layui-form">
						<label class="col-sm-2 control-label">模型类别：</label>
						<div class="col-sm-9">
							<?php if(!isset($info['type'])){ $info['type'] = '2'; }; ?>
							<input name="type" value="2" type="radio" lay-filter="hope" {if condition="$info.type eq '2'"}checked{/if} title="表单模型">
							<input name="type" value="1" type="radio" lay-filter="hope" {if condition="$info.type eq '1'"}checked{/if} title="内容拓展模型">
						</div>
					</div>
					<div class="form-group" id="sorttype">
						<label class="col-sm-2 control-label">列表排序：</label>
						<div class="col-sm-9">
							<input type="text" autocomplete="off" id="order_by" value="{$info.order_by}" name="order_by" class="form-control" placeholder="默认排序为 data_id desc ">
						</div>
					</div>
					<div class="form-group layui-form" id="tougao">
						<label class="col-sm-2 control-label">允许投稿：</label>
						<div class="col-sm-9">
							<?php if(!isset($info['is_post'])){ $info['is_post'] = 0; }; ?>
							<input name="is_post" value="1" type="radio" {if condition="$info.is_post eq '1'"}checked{/if} title="开启">
							<input name="is_post" value="0" type="radio" {if condition="$info.is_post eq '0'"}checked{/if} title="关闭">
						</div>
					</div>
					<div class="form-group layui-form">
						<label class="col-sm-2 control-label">状态：</label>
						<div class="col-sm-9">
							<?php if(!isset($info['status'])){ $info['status'] = 1; }; ?>
							<input name="status" value="1" type="radio" {if condition="$info.status eq '1'"}checked{/if} title="开启">
							<input name="status" value="0" type="radio" {if condition="$info.status eq '0'"}checked{/if} title="关闭">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">权重：</label>
						<div class="col-sm-9">
						<?php if(!isset($info['sortid'])){ $info['sortid'] = 100; }; ?>
							<input type="text" autocomplete="off" id="sortid" value="{$info.sortid}" name="sortid" class="form-control" placeholder="请输入排序">
						</div>
					</div>
				<!-- form end -->
				</div>
			</div>
			<div class="hr-line-dashed"></div>
			<div class="row btn-group-m-t">
				<div class="col-sm-9 col-sm-offset-1">
					<button type="button" class="btn btn-primary" onclick="{if condition="$extend_id eq ''"}CodeInfoDlg.add(){else/}CodeInfoDlg.update(){/if}" id="ensure">
						<i class="fa fa-check"></i>&nbsp;确认提交
					</button>
					<button type="button" class="btn btn-danger" onclick="CodeInfoDlg.close()" id="cancel">
						<i class="fa fa-eraser"></i>&nbsp;取消
					</button>
				</div>
			</div>
		</div>
	</div>
</div>
<script src="__PUBLIC__/static/js/upload.js" charset="utf-8"></script>
<script src="__PUBLIC__/static/js/plugins/layui/layui.js" charset="utf-8"></script>
<script>
layui.use(['form'],function(){
	form = layui.form;
	form.on('radio(hope)',function(data){
		if(data.value == 2){
			$("#tougao").show();
			$("#sorttype").show();
		}else{
			$("#tougao").hide();
			$("#sorttype").hide();
		}
	
	});	
});

$(function(){
	var type = $("input[name='type']:checked").val();
	if(type == 1){
		$("#tougao").hide();//默认第一个选中
		$("#sorttype").hide();//默认第一个选中
	}
})


var CodeInfoDlg = {
	CodeInfoData: {},
	validateFields: {
		title: {
			validators: {
				notEmpty: {
					message: '名称不能为空'
	 			},
	 		}
	 	},
	 }
}

CodeInfoDlg.collectData = function () {
	this.set('extend_id').set('title').set('table_name').set('order_by').set('sortid');
};

CodeInfoDlg.add = function () {
	 this.clearData();
	 this.collectData();
	 if (!this.validate()) {
	 	return;
	 }
	 var type = $("input[name = 'type']:checked").val();
	 var status = $("input[name = 'status']:checked").val();
	 var is_post = $("input[name = 'is_post']:checked").val();
	 var ajax = new $ax(Feng.ctxPath + "/Extend/add", function (data) {
	 	if ('00' === data.status) {
	 		Feng.success(data.msg,1000);
	 		window.parent.CodeGoods.table.refresh();
	 		CodeInfoDlg.close();
	 	} else {
	 		Feng.error(data.msg + "！",1000);
		 }
	 })
	 ajax.set('type',type);
	 ajax.set('status',status);
	 ajax.set('is_post',is_post);
	 ajax.set(this.CodeInfoData);
	 ajax.start();
};

CodeInfoDlg.update = function () {
	 this.clearData();
	 this.collectData();
	 if (!this.validate()) {
	 	return;
	 }
	 var type = $("input[name = 'type']:checked").val();
	 var status = $("input[name = 'status']:checked").val();
	 var is_post = $("input[name = 'is_post']:checked").val();
	 var ajax = new $ax(Feng.ctxPath + "/Extend/update", function (data) {
	 	if ('00' === data.status) {
	 		Feng.success(data.msg,1000);
	 		window.parent.CodeGoods.table.refresh();
	 		CodeInfoDlg.close();
	 	} else {
	 		Feng.error(data.msg + "！",1000);
		 }
	 })
	 ajax.set('type',type);
	 ajax.set('status',status);
	 ajax.set('is_post',is_post);
	 ajax.set(this.CodeInfoData);
	 ajax.start();
};


</script>
<script src="__PUBLIC__/static/js/base.js" charset="utf-8"></script>
{/block}
